package com.xiaoma.thread.locksupport;

import java.util.concurrent.locks.LockSupport;

public class LockSupportTest {

  public static class MyThread extends Thread{
    @Override
    public void  run(){

      System.out.println("myThread进入线程");
      LockSupport.park();
      System.out.println("myThread结束线程");
    }
  }

  public static void main(String[] args) throws InterruptedException {
/*    MyThread myThread=new MyThread();
    myThread.start();

    Thread.sleep(1000);
    System.out.println("开始unpark myThread");
    LockSupport.unpark(myThread);
    */

    Object lock=new Object();

    Thread thread1=new Thread(()->{
        System.out.println("park before.....");
        LockSupport.park();
      System.out.println("park after.....");
    });



    for (int i = 0; i < 10; i++) {
      Thread thread=new Thread(()->{
        synchronized (lock){
          System.out.println(Thread.currentThread().getName());
        }
      });
      thread.start();
    }

    thread1.start();
//    Thread.sleep(100);
//    System.out.println("unpark........");
//    LockSupport.unpark(thread1);

  }
}
